﻿using Hxj.Data;
using RecruitStudents.Utility.Model;
using RecruitStudents.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using RecruitStudents.Utility.Json;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Const;
using System.Net;
using System.Web;
using System.IO;
using System.Drawing;

namespace RecruitStudents.Client.BLL.Impl
{
    public class BLLExaminee
    {
        DAL.DALExaminee dal = new DAL.DALExaminee();
        DAL.DALComm daoComm = new DAL.DALComm();

        #region 新加的考试分组  上戏统考
        public void ExecuteNonQuery(string strSql)
        {
            dal.ExecuteNonQuery(strSql);
        }
        public DataTable GetTable(string strSql)
        {
            return dal.GetTable(strSql);
        }
        public JsonMessage SaveExamGroup(string strJson)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                TB_Examinee_ExamGroup model = strJson.ToList<TB_Examinee_ExamGroup>();
                model.CreateDate = DateTime.Now;
                dal.Save<TB_Examinee_ExamGroup>(model, trans);
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        #endregion


        #region 上戏考生成绩查询
        public DataSet GetExamineeScoreSearchFormExcel(string strExamPlaceNo, string strSpecNo, string strExamLevel,
            string strName, string strIdCard, string strNMT_SignUpID, string strExamRoomNo, string strExamYear,
            string strStartDate, string strEndDate)
        {

            using (DataSet ds = new DataSet())
            {
                DataTable dtTeacher = ServiceHelper.CreateCommService().GetTeacherList(strExamRoomNo);
                StringBuilder strText = null;
                string strExaminerName = "";
                string xh = "";
                foreach (DataRow dr in dtTeacher.Rows)
                {
                    xh = dr["XH"].ToString();
                    strExaminerName = dr["ExaminerName"].ToSafeString();
                    strText = new StringBuilder();
                    strText.Append("select ROW_NUMBER() OVER(order by CreateTime) Number,LotNO,Name,Sex,Score1,Score2,CreateTime from View_Pad_TeacherScoreList where LoginName='" + dr["LoginName"].ToSafeString() + "'");
                    strText.Append(" and SpecialityKindsNO='" + strSpecNo + "' and ExamRoomNO='" + strExamRoomNo + "'");
                    if (!strIdCard.IsNullOrEmptyString())
                    {
                        strText.Append(" and IdentityCard='" + strIdCard + "'");
                    }
                    if (!strNMT_SignUpID.IsNullOrEmptyString())
                    {
                        strText.Append(" and NMT_SignUpID='" + strNMT_SignUpID + "'");
                    }
                    if (!strName.IsNullOrEmptyString())
                    {
                        strText.Append(" and Name like '%" + strName + "%'");
                    }
                    if (!strStartDate.IsNullOrEmptyString())
                    {
                        strText.Append(" and CreateTime>='" + strStartDate.ToSafeDateTime() + "'");
                    }
                    if (!strEndDate.IsNullOrEmptyString())
                    {
                        strText.Append(" and CreateTime<'" + strEndDate.ToSafeDateTime().AddMinutes(1) + "'");
                    }
                    strText.Append(" order by CreateTime ");
                    using (DataTable dt = dal.GetTable(strText.ToString()))
                    {
                        dt.TableName = strExaminerName + "" + xh;
                        ds.Tables.Add(dt.Copy());
                    }
                }
                dtTeacher = null;
                return ds;
            }
        }



        public DataTable GetExamineeScoreSearchForm1(string strExamPlaceNo, string strSpecNo, string strExamLevel,
            string strName, string strIdCard, string strNMT_SignUpID, string strExamRoomNo, string strExamYear,
            string strStartDate, string strEndDate,string strAllowExamID)
        {
            string strSql = @" select * from View_Pad_StudentScoreList_All_1303010 as A";
            strSql += " where A.ExamYear='" + strExamYear + "'";
            if (!strAllowExamID.IsNullOrEmptyString())
            {
                strSql += " and A.AllowExamID='" + strAllowExamID + "'";
            }
            //if (!strStartDate.IsNullOrEmptyString())
            //{
            //    strSql += " and A.CreateTime>='" + strStartDate.ToSafeDateTime() + "'";
            //}
            //if (!strEndDate.IsNullOrEmptyString())
            //{
            //    strSql += " and A.CreateTime<'" + strEndDate.ToSafeDateTime().AddMinutes(1) + "'";
            //}
            if (!strExamPlaceNo.IsNullOrEmptyString())
            {
                strSql += " and A.ExamPlaceNO='" + strExamPlaceNo + "'";
            }
            //if (!strExamLevel.IsNullOrEmptyString())
            //{
            //    strSql += " and A.ExamLevel='" + strExamLevel + "'";
            //}
            if (!strName.IsNullOrEmptyString())
            {
                strSql += " and A.Name like '%" + strName + "%'";
            }
            if (!strIdCard.IsNullOrEmptyString())
            {
                strSql += " and A.IdentityCard='" + strIdCard + "'";
            }
            if (!strNMT_SignUpID.IsNullOrEmptyString())
            {
                strSql += " and A.NMT_SignUpID='" + strNMT_SignUpID + "'";
            }
            if (!strSpecNo.IsNullOrEmptyString())
            {
                strSql += " and A.SpecialityKindsNO like '" + strSpecNo + "%' ";
                //strSql += " and A.SpecialityKindsNO in (" + strSpecNo + ") ";
            }
            //if (!strExamRoomNo.IsNullOrEmptyString())
            //{
            //    strSql += " and A.ExamRoomNo='" + strExamRoomNo + "'  ";
            //}
            //strSql += " order by A.LotNo ";
            return dal.GetTable(strSql);
        }


        public DataTable GetExamineeScoreSearchForm2(string strExamPlaceNo, string strSpecNo, string strExamLevel,
            string strName, string strIdCard, string strNMT_SignUpID, string strExamRoomNo, string strExamYear,
            string strStartDate, string strEndDate,string strAllowExamID)
        {
            string strSql = @" select * from View_Pad_StudentScoreList_All_1303090  as A ";

            strSql += " where A.ExamYear='" + strExamYear + "'";
            if (!strAllowExamID.IsNullOrEmptyString())
            {
                strSql += " and A.AllowExamID='" + strAllowExamID + "'";
            }
            //if (!strStartDate.IsNullOrEmptyString())
            //{
            //    strSql += " and A.CreateTime>='" + strStartDate.ToSafeDateTime() + "'";
            //}
            //if (!strEndDate.IsNullOrEmptyString())
            //{
            //    strSql += " and A.CreateTime<='" + strEndDate.ToSafeDateTime() + "'";
            //}
            if (!strExamPlaceNo.IsNullOrEmptyString())
            {
                strSql += " and A.ExamPlaceNO='" + strExamPlaceNo + "'";
            }
            //if (!strExamLevel.IsNullOrEmptyString())
            //{
            //    strSql += " and A.ExamLevel='" + strExamLevel + "'";
            //}
            if (!strName.IsNullOrEmptyString())
            {
                strSql += " and A.Name like '%" + strName + "%'";
            }
            if (!strIdCard.IsNullOrEmptyString())
            {
                strSql += " and A.IdentityCard='" + strIdCard + "'";
            }
            if (!strNMT_SignUpID.IsNullOrEmptyString())
            {
                strSql += " and A.NMT_SignUpID='" + strNMT_SignUpID + "'";
            }
            if (!strSpecNo.IsNullOrEmptyString())
            {
                strSql += " and A.SpecialityKindsNO like '" + strSpecNo + "%' ";
                //strSql += " and A.SpecialityKindsNO in (" + strSpecNo + ") ";
            }
            if (!strExamRoomNo.IsNullOrEmptyString())
            {
                //strSql += " and A.ExamRoomNo='" + strExamRoomNo + "'  ";
            }
            //strSql += " order by A.LotNo ";
            return dal.GetTable(strSql);
        }


        public DataTable GetExamineeScoreSearchForm3(string strExamPlaceNo, string strSpecNo, string strExamLevel,
            string strName, string strIdCard, string strNMT_SignUpID, string strExamRoomNo, string strExamYear,
            string strStartDate, string strEndDate,string strAllowExamID)
        {
            string strSql = @" select * from View_Pad_StudentScoreList_SingleDetail  as A ";
            strSql += " where A.ExamYear='" + strExamYear + "'";
            if (!strAllowExamID.IsNullOrEmptyString())
            {
                strSql += " and A.AllowExamID='" + strAllowExamID + "'";
            }
            if (!strStartDate.IsNullOrEmptyString())
            {
                strSql += " and A.CreateTime>='" + strStartDate.ToSafeDateTime() + "'";
            }
            if (!strEndDate.IsNullOrEmptyString())
            {
                strSql += " and A.CreateTime<='" + strEndDate.ToSafeDateTime() + "'";
            }
            if (!strExamPlaceNo.IsNullOrEmptyString())
            {
                strSql += " and A.ExamPlaceNO='" + strExamPlaceNo + "'";
            }
            if (!strExamLevel.IsNullOrEmptyString())
            {
                strSql += " and A.ExamLevel='" + strExamLevel + "'";
            }
            if (!strName.IsNullOrEmptyString())
            {
                strSql += " and A.Name like '%" + strName + "%'";
            }
            if (!strIdCard.IsNullOrEmptyString())
            {
                strSql += " and A.IdentityCard='" + strIdCard + "'";
            }
            if (!strNMT_SignUpID.IsNullOrEmptyString())
            {
                strSql += " and A.NMT_SignUpID='" + strNMT_SignUpID + "'";
            }
            if (!strSpecNo.IsNullOrEmptyString())
            {
                strSql += " and A.SpecialityKindsNO like '" + strSpecNo + "%' ";
                //strSql += " and A.SpecialityKindsNO in (" + strSpecNo + ") ";
            }
            if (!strExamRoomNo.IsNullOrEmptyString())
            {
                strSql += " and A.ExamRoomNo='" + strExamRoomNo + "'  ";
            }
            strSql += " order by A.LotNo ";
            return dal.GetTable(strSql);
        }


        #endregion




        #region 获取考试信息导出excel
        public DataTable GetSignUpStudentsByExcel_New(string strExamRoomNo)
        {
            string strSql = @"select
	                A.AllowExamID,
	                B.Name,
	                B.NMT_SignUpID,
	                B.IdentityCard,
	                CASE WHEN B.Sex = '1' THEN '男' else '女' end as sec,
	                D.DicName,
	                F.Teacher1Name + ':' + cast(F.Score1 as varchar(10)) as Score1,
	                F.Teacher2Name + ':' + cast(F.Score2 as varchar(10)) as Score2,
	                F.Teacher3Name + ':' + cast(F.Score3 as varchar(10)) as Score3,
	                F.Teacher4Name + ':' + cast(F.Score4 as varchar(10)) as Score4,
	                F.Teacher5Name + ':' + cast(F.Score5 as varchar(10)) as Score5,
	                F.Teacher6Name + ':' + cast(F.Score6 as varchar(10)) as Score6,
	                F.Teacher7Name + ':' + cast(F.Score7 as varchar(10)) as Score7,
                    F.TatolScore
                from  TB_Exam_SignUpStudentsSpeciality	A 
                left join TB_SignUpStudents				B ON A.SignUpID = B.SignUpID 
                left join TB_Sys_SpecialityKinds		C ON A.SpecialityKindsNO = C.SpecialityKindsNO 
                left join TB_Dic_ExamProvince			D ON D.DicNO = B.ExamProvince 
                left join TB_Exam_Signed				E ON A.SignUpStudentsSpecialityID = E.SignUpStudentsSpecialityID 
                left join TB_Pad_StudentScoreList		F ON E.SignedID = F.SignedID 
                where A.SpecialityKindsNO in (select SpecialityKindsNO from TB_Exam_Entretenimientoh where EntretenimientohID in (select EntretenimientohID from TB_Exam_ExamRoom where ExamRoomNO='{0}'))  
                order by AllowExamID asc
            ";
            return dal.GetTable(string.Format(strSql, strExamRoomNo));
        }

        public DataTable GetSpecialityExameeSearchDataTable(string strExamPlaceNo, string strSpecNo, string strExamLevel,
            string strName, string strIdCard, string strNMT_SignUpID, string strExamRoomNo, string strExamYear)
        {
            string strSql = @"
                select a.*,b.AllowExamID,b.ExamLevel,b.ExamPlaceNO,b.SpecialityKindsID,b.SpecialityKindsNameAS as SpecialityKindsName,b.ExamStateNew,
                c.DicName,d.DicName as ExamLevelName,e.ExamPlaceName
                from TB_SignUpStudents as a 
                left join (
                    select distinct SpecialityKindsID, SpecialityKindsNameAS, b.ExamLevel, b.AllowExamID, b.SignUpID, b.ExamPlaceNO,ISNULL(b.ExamState,0) as ExamStateNew from TB_Sys_SpecialityKinds as a
                    left join TB_Exam_SignUpStudentsSpeciality as b on a.SpecialityKindsNO = b.SpecialityKindsNO where 1=1 {0}
                ) as b on a.SignUpID = b.SignUpID
                left join TB_Dic_ExamProvince as c on a.ExamProvince = c.DicNO
                left join TB_Dic_ExamLevel as d on d.DicNO = b.ExamLevel
                left join TB_Sys_ExamPlace as e on e.ExamPlaceNO=b.ExamPlaceNO  where b.SpecialityKindsID is not null 
            ";
            strSql += " and a.ExamYear='" + strExamYear + "'";
            if (!strExamPlaceNo.IsNullOrEmptyString())
            {
                strSql += " and b.ExamPlaceNO='" + strExamPlaceNo + "'";
            }
            if (!strExamLevel.IsNullOrEmptyString())
            {
                strSql += " and b.ExamLevel='" + strExamLevel + "'";
            }
            if (!strName.IsNullOrEmptyString())
            {
                strSql += " and a.Name like '%" + strName + "%'";
            }
            if (!strIdCard.IsNullOrEmptyString())
            {
                strSql += " and a.IdentityCard='" + strIdCard + "'";
            }
            if (!strNMT_SignUpID.IsNullOrEmptyString())
            {
                strSql += " and a.NMT_SignUpID='" + strNMT_SignUpID + "'";
            }
            string strSpecWhere = "";
            if (!strSpecNo.IsNullOrEmptyString())
            {
                strSpecWhere = " and b.SpecialityKindsNO in (" + strSpecNo + ") ";
            }
            if (!strExamRoomNo.IsNullOrEmptyString())
            {
                strSpecWhere += " and b.SpecialityKindsNO in (select SpecialityKindsNO from TB_Exam_Entretenimientoh where EntretenimientohID in (select EntretenimientohID from TB_Exam_ExamRoom where ExamRoomNO='" + strExamRoomNo + "'))  ";
            }
            strSql = string.Format(strSql, strSpecWhere);
            strSql += " order by b.ExamStateNew desc";
            return dal.GetTable(strSql);
        }

        public DataTable GetExameeSpeciality_ExamLevelBySignUpID_New(string strSignUpID)
        {
            return dal.GetExameeSpeciality_ExamLevelBySignUpID_New(strSignUpID);
        }
        #endregion

        #region 根据高考报名号获取生源地
        public DataTable Check_SYD_By_YKZ(string strYKZ)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_Dic_NMT_SignUp._.Mask == strYKZ);
            return dal.GetTable<TB_Dic_NMT_SignUp>(clip);
        }
        #endregion

        #region  根据考生号查询，判断考生号是否已经存在
        public DataTable GetStudentsInfoByYKZ(string strNMT_SignUpID)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_SignUpStudents._.NMT_SignUpID == strNMT_SignUpID);
            return dal.GetTable<TB_SignUpStudents>(clip);
        }
        #endregion

        #region 根据考生号长度查询，获取生源地映射信息
        public DataTable GetNativePlaceNOByLen(string strNMT_SignUp_Len)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Dic_NMT_SignUp._.NMT_SignUp_Len == strNMT_SignUp_Len);
            return dal.GetTable<TB_Dic_NMT_SignUp>(wcp);
        }
        #endregion

        #region 根据考生匹配内容获取生源地信息
        public DataTable GetNativePlaceNOByMask(string strMask)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Dic_NMT_SignUp._.Mask == strMask);
            return dal.GetTable<TB_Dic_NMT_SignUp>(wcp);
        }
        #endregion

        #region  根据考点编号获取受限制的考点
        public DataTable GetExamPlace_Limit(string strExamPlaceNO)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_Sys_ExamPlace_Limit._.ExamPlaceNO == strExamPlaceNO);
            return dal.GetTable<TB_Sys_ExamPlace_Limit>(clip);
        }
        #endregion

        #region 获取 考生基本信息(根据考生ID)
        public TB_SignUpStudents GetExameeByID(string strSignUpID)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_SignUpStudents._.SignUpID == strSignUpID);
            return dal.GetModel<TB_SignUpStudents>(clip);
        }
        #endregion

        #region 获取 考生基本信息(根据高考报名号)
        public DataTable GetExameeByNMT_SignUpID(string strNMT_SignUpID)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_SignUpStudents._.NMT_SignUpID == strNMT_SignUpID);
            return dal.GetTable<TB_SignUpStudents>(clip);
        }
        #endregion

        #region 获取 考生基本信息(根据身份证号)
        public DataTable GetExameeByIdentityCard(string strIdentityCard)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_SignUpStudents._.IdentityCard == strIdentityCard);
            return dal.GetTable<TB_SignUpStudents>(clip);
        }
        #endregion

        #region 获取 考生缴费信息（找出相应专业的缴费情况）
        public DataTable GetExameeNetPayFeeDataTable_New(string strIdentityCard)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsActive == "1");
            clip = clip.And(TB_SignUpStudents._.IdentityCard == strIdentityCard);
            return dal.GetExameeNetPayFeeDataTable_New(clip);
        }

        #endregion

        #region 获取 考生报考专业 财务订单付款信息(根据考生ID)
        public DataTable GetExameeSpeciality_NetPayFeeInfo_BySignUpID(string strSignUpID)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.SignUpID == strSignUpID);
            clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsActive == "1");
            return dal.GetExameeSpeciality_NetPayFeeInfo_BySignUpID(clip);
        }
        #endregion

        #region 获取 财务订单付款信息(根据考生ID)
        public DataTable GetNetPayFeeInfo_BySignUpID(string strSignUpID)
        {
            WhereClip clip = new WhereClip();
            if (!string.IsNullOrEmpty(strSignUpID))
            {
                clip = clip.And(TB_SignUpStudentsNetPayFee_Head._.SignUpID == strSignUpID);
            }
            return dal.GetNetPayFeeInfo_BySignUpID(clip);
        }
        #endregion

        #region 获取 财务订单明细(根据订单号)
        public DataTable GetNetPayFeeDetail_ByOrdNO(string strOrdNO)
        {
            WhereClip clip = new WhereClip();
            if (!string.IsNullOrEmpty(strOrdNO))
            {
                clip = clip.And(TB_SignUpStudentsNetPayFee_Detail._.OrdNO == strOrdNO);
            }
            return dal.GetNetPayFeeDetail_ByOrdNO(clip);
        }
        #endregion

        #region 获取 考生报考专业,考试级别(根据考生ID)
        public DataTable GetExameeSpeciality_ExamLevelBySignUpID(string strSignUpID)
        {
            WhereClip clip = new WhereClip();
            if (!string.IsNullOrEmpty(strSignUpID))
            {
                clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.SignUpID == strSignUpID);
            }
            clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsActive == "1");
            return dal.GetExameeSpeciality_ExamLevelBySignUpID(clip);
        }
        #endregion

        #region 获取 考生报考专业(根据考生ID)
        public DataTable GetExameeSpecialityBySignUpID(string strSignUpID)
        {
            WhereClip clip = new WhereClip();
            if (!string.IsNullOrEmpty(strSignUpID))
            {
                clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.SignUpID == strSignUpID);
            }
            clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsActive == "1");
            clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsFee_First == "1");
            //DeleteExamSignUpStudentsSpecialityBySignUpID(strSignUpID, "0"); //删除未交费的信息（此处添加删除方法）
            return dal.GetTable<TB_Exam_SignUpStudentsSpeciality>(clip);
        }
        #endregion

        #region  根据考生ID删除报考专业信息
        public JsonMessage DeleteExamSignUpStudentsSpecialityBySignUpID(string strSignUpID, string strIsFee)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                WhereClip where = new WhereClip();
                where = where.And(TB_Exam_SignUpStudentsSpeciality._.SignUpID == strSignUpID);
                where = where.And(TB_Exam_SignUpStudentsSpeciality._.IsFee_First == strIsFee);
                dal.Delete<TB_Exam_SignUpStudentsSpeciality>(where);
                message.State = "true";
                message.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "操作失败:" + ex.Message;
            }
            return message;
        }
        #endregion

        #region 获取 考点、专业、分组关联信息
        public DataTable GetSpecialityKindsDataTable(string strExamPlaceNO)
        {
            WhereClip clip = new WhereClip();

            if (!string.IsNullOrEmpty(strExamPlaceNO))
            {
                clip = clip.And(View_ExamPlaceSpecialityKindsGroupMapping_ByLocale._.ExamPlaceNO == strExamPlaceNO);
            }
            return dal.GetTable<View_ExamPlaceSpecialityKindsGroupMapping_ByLocale>(clip);
        }
        #endregion

        #region 获取考生照片
        public DataSet GetStudentsPhoto(string strSignUpStudentsID)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_SignUpStudentsPhoto._.SignUpStudentsID == strSignUpStudentsID);
            return dal.GetDataSet<TB_SignUpStudentsPhoto>(clip);
        }
        #endregion

        #region 保存考生基本信息
        public JsonMessage SaveStudentInfo_Modify(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_SignUpStudents model = strJson.ToList<TB_SignUpStudents>();
                dal.Save<TB_SignUpStudents>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            return message;
        }
        #endregion

        #region 保存 考生信息（学生基本信息 咨询互动用户表  报考专业信息  财务订单付款  财务订单明细 打印表）
        public JsonMessage SaveSignUpStudentsInfo(string strJson)
        {
            Dictionary<string, string> serchList = JsonHelper.JsonToObject<Dictionary<string, string>>(strJson);
            string strJsonprintListModel = serchList["strJsonprintListModel"];
            string strJsonSignUpStudentsModel = serchList["strJsonSignUpStudentsModel"];
            string strJsonConsultUsersModel = serchList["strJsonConsultUsersModel"];
            string strJsonPayFeeModel = serchList["strJsonPayFeeModel"];
            string strJsonPayFee_DetailList = serchList["strJsonPayFee_DetailList"];
            string strJsonStudentsSpeciality = serchList["strJsonStudentsSpeciality"];

            TB_PrintList PrintListModel = JsonHelper.JsonDeserialize<TB_PrintList>(strJsonprintListModel);
            TB_SignUpStudents SignUpStudentsModel = JsonHelper.JsonDeserialize<TB_SignUpStudents>(strJsonSignUpStudentsModel);
            TB_ConsultUsers ConsultUsersModel = JsonHelper.JsonDeserialize<TB_ConsultUsers>(strJsonConsultUsersModel);
            TB_SignUpStudentsNetPayFee_Head PayFeeModel = JsonHelper.JsonDeserialize<TB_SignUpStudentsNetPayFee_Head>(strJsonPayFeeModel);
            List<TB_SignUpStudentsNetPayFee_Detail> PayFee_Detaillist = JsonHelper.JsonToObject<List<TB_SignUpStudentsNetPayFee_Detail>>(strJsonPayFee_DetailList);
            List<TB_Exam_SignUpStudentsSpeciality> StudentsSpecialitylist = JsonHelper.JsonToObject<List<TB_Exam_SignUpStudentsSpeciality>>(strJsonStudentsSpeciality);

            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                dal.Save<TB_SignUpStudents>(SignUpStudentsModel, trans);
                if (StudentsSpecialitylist != null && StudentsSpecialitylist.Count > 0)
                {
                    for (int i = 0; i < StudentsSpecialitylist.Count; i++)
                    {
                        dal.Save<TB_Exam_SignUpStudentsSpeciality>(StudentsSpecialitylist[i], trans);
                    }
                }
                dal.Save<TB_ConsultUsers>(ConsultUsersModel, trans);
                dal.Save<TB_SignUpStudentsNetPayFee_Head>(PayFeeModel, trans);
                if (PayFee_Detaillist != null && PayFee_Detaillist.Count > 0)
                {
                    for (int i = 0; i < PayFee_Detaillist.Count; i++)
                    {
                        dal.Save<TB_SignUpStudentsNetPayFee_Detail>(PayFee_Detaillist[i], trans);
                    }
                }
                dal.Save<TB_PrintList>(PrintListModel, trans);
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }
        #endregion

        #region  保存专业补报信息（报考专业信息  财务订单付款  财务订单明细）
        public JsonMessage SavaSpecialityPackInfo(string strJson)
        {
            Dictionary<string, string> serchList = JsonHelper.JsonToObject<Dictionary<string, string>>(strJson);
            string strJsonPayFeeModel = serchList["strJsonPayFeeModel"];
            string strJsonPayFee_DetailList = serchList["strJsonPayFee_DetailList"];
            string strJsonStudentsSpeciality = serchList["strJsonStudentsSpeciality"];
            string strJsonprintListModel = serchList["strJsonprintListModel"];

            TB_PrintList PrintListModel = JsonHelper.JsonDeserialize<TB_PrintList>(strJsonprintListModel);
            TB_SignUpStudentsNetPayFee_Head PayFeeModel = JsonHelper.JsonDeserialize<TB_SignUpStudentsNetPayFee_Head>(strJsonPayFeeModel);
            List<TB_SignUpStudentsNetPayFee_Detail> PayFee_Detaillist = JsonHelper.JsonToObject<List<TB_SignUpStudentsNetPayFee_Detail>>(strJsonPayFee_DetailList);
            List<TB_Exam_SignUpStudentsSpeciality> StudentsSpecialitylist = JsonHelper.JsonToObject<List<TB_Exam_SignUpStudentsSpeciality>>(strJsonStudentsSpeciality);


            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                if (StudentsSpecialitylist != null && StudentsSpecialitylist.Count > 0)
                {
                    for (int i = 0; i < StudentsSpecialitylist.Count; i++)
                    {
                        dal.Save<TB_Exam_SignUpStudentsSpeciality>(StudentsSpecialitylist[i], trans);
                    }
                }
                dal.Save<TB_SignUpStudentsNetPayFee_Head>(PayFeeModel, trans);
                if (PayFee_Detaillist != null && PayFee_Detaillist.Count > 0)
                {
                    for (int i = 0; i < PayFee_Detaillist.Count; i++)
                    {
                        dal.Save<TB_SignUpStudentsNetPayFee_Detail>(PayFee_Detaillist[i], trans);
                    }
                }
                dal.Save<TB_PrintList>(PrintListModel, trans);
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }
        #endregion

        #region 保存缴费确认信息（更新报考专业信息  保存财务订单付款  保存财务订单明细）
        public JsonMessage UpdateSpecialityInfoState(string strJson)
        {
            Dictionary<string, string> serchList = JsonHelper.JsonToObject<Dictionary<string, string>>(strJson);
            string strJsonPayFeeModel = serchList["strJsonPayFeeModel"];
            string strJsonPayFee_DetailList = serchList["strJsonPayFee_DetailList"];
            string strJsonStudentsSpeciality = serchList["strJsonStudentsSpeciality"];
            string strJsonprintListModel = serchList["strJsonprintListModel"];

            TB_PrintList printListModel = JsonHelper.JsonDeserialize<TB_PrintList>(strJsonprintListModel);
            TB_SignUpStudentsNetPayFee_Head PayFeeModel = JsonHelper.JsonDeserialize<TB_SignUpStudentsNetPayFee_Head>(strJsonPayFeeModel);
            List<TB_SignUpStudentsNetPayFee_Detail> PayFee_Detaillist = JsonHelper.JsonToObject<List<TB_SignUpStudentsNetPayFee_Detail>>(strJsonPayFee_DetailList);
            List<TB_Exam_SignUpStudentsSpeciality> StudentsSpecialitylist = JsonHelper.JsonToObject<List<TB_Exam_SignUpStudentsSpeciality>>(strJsonStudentsSpeciality);

            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                dal.Save<TB_PrintList>(printListModel, trans);
                dal.Save<TB_SignUpStudentsNetPayFee_Head>(PayFeeModel, trans);
                if (PayFee_Detaillist != null && PayFee_Detaillist.Count > 0)
                {
                    for (int i = 0; i < PayFee_Detaillist.Count; i++)
                    {
                        dal.Save<TB_SignUpStudentsNetPayFee_Detail>(PayFee_Detaillist[i], trans);
                    }
                }
                dal.UpdateSpecialityInfoState(StudentsSpecialitylist, trans);
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }
        #endregion

        #region 上传照片
        public JsonMessage UploadPhoto(string strSignUpID, string strPicData)
        {
            JsonMessage message = new JsonMessage();
            var model = dal.GetModel<TB_SignUpStudentsPhoto>(TB_SignUpStudentsPhoto._.SignUpStudentsID == strSignUpID);
            if (model == null)
            {
                byte[] buffer = Convert.FromBase64String(strPicData);
                var photoName = DateTime.Now.ToString("yyyyMMddhhmmssff") + ".bmp";
                model = new TB_SignUpStudentsPhoto();
                model.SignUpStudentsID = strSignUpID;
                model.Photo = buffer;
                model.PhotoSize = buffer.Length.ToString();
                model.PhotoSuffix = "bmp";
                model.PhotoName = photoName;
                var flag = false;
                DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
                try
                {
                    dal.ExecuteNonQuery("delete TB_SignUpStudentsPhoto where SignUpStudentsID='" + strSignUpID + "'", trans);
                    dal.Save<TB_SignUpStudentsPhoto>(model, trans);
                    trans.Commit();
                    flag = true;
                    message.State = "true";
                    message.Msg = "";
                }
                catch (Exception ex)
                {
                    message.State = "true";
                    message.Msg = ex.Message;
                    trans.Rollback();
                }
                finally
                {
                    trans.Close();
                }
                if (flag)
                {
                    string saveFileName = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "/Images/" + photoName;
                    if (System.IO.File.Exists(saveFileName))
                    {
                        System.IO.File.Delete(saveFileName);
                    }
                    using (MemoryStream buf = new MemoryStream(buffer))
                    {
                        Image image = Image.FromStream(buf, true);
                        image.Save(saveFileName);
                    }
                }
            }
            return message;
        }
        #endregion

        #region 打印准考证
        public JsonMessage UpdatePrintAllowExamIDData_All(string strSignUpID, string strComputerName)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                string sql = @" 
                            update TB_Exam_SignUpStudentsSpeciality set IsAllowExamCreate = '0',IsAllowExamDown='0',AllowExamDownDate=NULL where SignUpID = '{0}'
                            insert into TB_PrintList(PrintListNO,SignUpID,CreateTime,ComputerName,IsPrint) values(NewID(),'{0}',getdate(),'{1}','1')
                        ";
                sql = string.Format(sql, strSignUpID, strComputerName);
                dal.ExecuteNonQuery(sql);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }
        #endregion

        #region 获取考试信息导出excel
        public DataTable GetSignUpStudentsByExcel(string strExamPlaceID, string strExamLevel, string strSpecialityKindsNO)
        {
            string strSql = @"select
	            A.AllowExamID,
	            B.Name,
	            B.NMT_SignUpID,
	            B.IdentityCard,
	            CASE WHEN B.Sex = '1' THEN '男' else '女' end as sec,
	            D.DicName
                --,C.SpecialityKindsName 
            from dbo.TB_Exam_SignUpStudentsSpeciality	A 
            left join dbo.TB_SignUpStudents				B ON A.SignUpID = B.SignUpID 
            left join dbo.TB_Sys_SpecialityKinds		C ON A.SpecialityKindsNO = C.SpecialityKindsNO 
            left join dbo.TB_Dic_ExamProvince			D ON D.DicNO = B.ExamProvince 
            where A.AllowExamID is not null and A.ExamPlaceNO = '{0}' and A.IsActive = '1'  
	              and ExamLevel ='{1}' and A.SpecialityKindsNO = '{2}'   
            order by A.SpecialityKindsNO,A.AllowExamID  
            ";
            return dal.GetTable(string.Format(strSql, strExamPlaceID, strExamLevel, strSpecialityKindsNO));
        }
        #endregion

        #region 获取 考生相关信息（专业信息查询）
        public PagerCondition GetExamineeOfAllInfo(string strExamPlaceID, string strSpecialityKindsNO, string strAppointmentGroup, string strPaySource, string strIsPass,
            string strIsDownload, string strExamLevel, string strName, string strNMT_SignUpID, string strIdCard, string strAllowExamID,
            string strCurrentIndex, string strPageSize)
        {
            WhereClip clip = new WhereClip();
            if (!string.IsNullOrEmpty(strExamPlaceID))
            {
                clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.ExamPlaceNO == strExamPlaceID);
            }
            if (!string.IsNullOrEmpty(strSpecialityKindsNO))
            {
                clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.SpecialityKindsNO == strSpecialityKindsNO);
            }
            if (!string.IsNullOrEmpty(strIsPass))
            {
                if (strIsPass == "0")
                {
                    clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsPass.IsNull() || TB_Exam_SignUpStudentsSpeciality._.IsPass == strIsPass);
                }
                else
                {
                    clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsPass == strIsPass);
                }
            }
            if (!string.IsNullOrEmpty(strIsDownload))
            {
                if (strIsDownload == "0")
                {
                    clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsPassPaperDown.IsNull() || TB_Exam_SignUpStudentsSpeciality._.IsPassPaperDown == strIsDownload);
                }
                else
                {
                    clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.IsPassPaperDown == strIsDownload);
                }
            }
            if (!string.IsNullOrEmpty(strAllowExamID))
            {
                clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.AllowExamID.Contain(strAllowExamID));
            }
            if (!string.IsNullOrEmpty(strName))
            {
                clip = clip.And(TB_SignUpStudents._.Name.Contain(strName));
            }
            if (!string.IsNullOrEmpty(strNMT_SignUpID))
            {
                clip = clip.And(TB_SignUpStudents._.NMT_SignUpID.Contain(strNMT_SignUpID));
            }
            if (!string.IsNullOrEmpty(strIdCard))
            {
                clip = clip.And(TB_SignUpStudents._.IdentityCard.Contain(strIdCard));
            }
            if (!string.IsNullOrEmpty(strExamLevel))
            {
                if (strExamLevel == "1")
                {
                    if (!string.IsNullOrEmpty(strAppointmentGroup))
                    {
                        clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.AppointmentGroup_First == strAppointmentGroup);
                    }
                    clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.ExamLevel >= 0);
                    if (!string.IsNullOrEmpty(strPaySource))
                    {
                        clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.OrderNo_First.SubQueryIn(
                             DbHelper.GetDatabase().From<TB_SignUpStudentsNetPayFee_Head>()
                           .Select(TB_SignUpStudentsNetPayFee_Head._.OrdNO)
                            .Where(TB_SignUpStudentsNetPayFee_Head._.PaySource == strPaySource)
                            ));
                    }
                }
                else if (strExamLevel == "2")
                {
                    if (!string.IsNullOrEmpty(strAppointmentGroup))
                    {
                        clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.AppointmentGroup_First == strAppointmentGroup);
                    }
                    clip = clip.And((TB_Exam_SignUpStudentsSpeciality._.ExamLevel == 1 && TB_Exam_SignUpStudentsSpeciality._.IsPass == "1") || (TB_Exam_SignUpStudentsSpeciality._.ExamLevel >= 2));

                    if (!string.IsNullOrEmpty(strPaySource))
                    {
                        clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.OrderNo_Second.SubQueryIn(
                            DbHelper.GetDatabase().From<TB_SignUpStudentsNetPayFee_Head>()
                          .Select(TB_SignUpStudentsNetPayFee_Head._.OrdNO)
                           .Where(TB_SignUpStudentsNetPayFee_Head._.PaySource == strPaySource)
                           ));
                    }
                }
                else if (strExamLevel == "3")
                {
                    if (!string.IsNullOrEmpty(strAppointmentGroup))
                    {
                        clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.AppointmentGroup_First == strAppointmentGroup);
                    }
                    clip = clip.And((TB_Exam_SignUpStudentsSpeciality._.ExamLevel == 2 && TB_Exam_SignUpStudentsSpeciality._.IsPass == "1") || (TB_Exam_SignUpStudentsSpeciality._.ExamLevel == 2));
                    if (!string.IsNullOrEmpty(strPaySource))
                    {
                        clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.OrderNo_Third.SubQueryIn(
                            DbHelper.GetDatabase().From<TB_SignUpStudentsNetPayFee_Head>()
                          .Select(TB_SignUpStudentsNetPayFee_Head._.OrdNO)
                           .Where(TB_SignUpStudentsNetPayFee_Head._.PaySource == strPaySource)
                           ));
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(strPaySource))
                {
                    clip = clip.And(TB_Exam_SignUpStudentsSpeciality._.OrderNo_First.SubQueryIn(
                            DbHelper.GetDatabase().From<TB_SignUpStudentsNetPayFee_Head>()
                          .Select(TB_SignUpStudentsNetPayFee_Head._.OrdNO)
                           .Where(TB_SignUpStudentsNetPayFee_Head._.PaySource == strPaySource))
                           || TB_Exam_SignUpStudentsSpeciality._.OrderNo_Second.SubQueryIn(
                            DbHelper.GetDatabase().From<TB_SignUpStudentsNetPayFee_Head>()
                          .Select(TB_SignUpStudentsNetPayFee_Head._.OrdNO)
                           .Where(TB_SignUpStudentsNetPayFee_Head._.PaySource == strPaySource))
                          || TB_Exam_SignUpStudentsSpeciality._.OrderNo_Third.SubQueryIn(
                            DbHelper.GetDatabase().From<TB_SignUpStudentsNetPayFee_Head>()
                          .Select(TB_SignUpStudentsNetPayFee_Head._.OrdNO)
                           .Where(TB_SignUpStudentsNetPayFee_Head._.PaySource == strPaySource))
                           );
                }
            }
            PagerCondition pager = new PagerCondition();
            pager.CurrentPage = strCurrentIndex.ToSafeInt();
            pager.PageSize = strPageSize.ToSafeInt();
            pager.ComplexSearchCondition = clip;
            pager.OrderBy = new OrderByClip(TB_Exam_SignUpStudentsSpeciality._.CreatTime, OrderByOperater.DESC);
            pager.DataJson = dal.GetExamineeOfAllInfo(pager, strExamLevel).ToJson();
            return pager;
        }
        #endregion

        #region 获取 考生相关信息（考生信息查询）
        public PagerCondition GetExamineeOfAllInfo_ByBaseInfo(string strName, string strNMT_SignUpID, string strIdCard, string strCurrentIndex, string strPageSize, string strExamYear)
        {
            PagerCondition pager = new PagerCondition();
            WhereClip clip = new WhereClip();
            clip = clip.And(TB_SignUpStudents._.ExamYear == strExamYear);
            if (!string.IsNullOrEmpty(strName))
            {
                clip = clip.And(TB_SignUpStudents._.Name.Contain(strName));
            }
            if (!string.IsNullOrEmpty(strNMT_SignUpID))
            {
                clip = clip.And(TB_SignUpStudents._.NMT_SignUpID.Contain(strNMT_SignUpID));
            }
            if (!string.IsNullOrEmpty(strIdCard))
            {
                clip = clip.And(TB_SignUpStudents._.IdentityCard.Contain(strIdCard));
            }
            pager.CurrentPage = strCurrentIndex.ToSafeInt();
            pager.PageSize = strPageSize.ToSafeInt();
            pager.ComplexSearchCondition = clip;
            pager.OrderBy = new OrderByClip(TB_SignUpStudents._.Name);
            pager.DataJson = dal.GetExamineeOfAllInfo_ByBaseInfo(pager).ToJson();
            return pager;
        }
        #endregion

        #region 获取 考试时间(通用方法)
        public string GetExamTime(string strExamPlaceNo, string strSpecialityKindsNO)
        {
            WhereClip clip = new WhereClip();
            clip = clip.And(View_ExamPlaceSpecialityKindsGroupMapping._.ExamPlaceNO == strExamPlaceNo);
            clip = clip.And(View_ExamPlaceSpecialityKindsGroupMapping._.SpecialityKindsNO == strSpecialityKindsNO);
            clip = clip.And(View_ExamPlaceSpecialityKindsGroupMapping._.ActualAcount < View_ExamPlaceSpecialityKindsGroupMapping._.TotalAcount);
            string strExamTime = "";
            try
            {
                DataTable dt = DbHelper.GetDatabase().From<View_ExamPlaceSpecialityKindsGroupMapping>() //选择表
                                       .Select(View_ExamPlaceSpecialityKindsGroupMapping._.All)  //设置选择的字段数目 
                                       .Where(clip)
                                       .OrderBy(new OrderByClip(View_ExamPlaceSpecialityKindsGroupMapping._.Sort))
                                       .ToDataTable();   //返回List

                if (dt.Rows.Count > 0)
                {
                    strExamTime = dt.Rows[0]["GroupNo"].ToString().Trim();
                }
                else
                {
                    WhereClip clip2 = new WhereClip();
                    clip2 = clip2.And(View_ExamPlaceSpecialityKindsGroupMapping._.ExamPlaceNO == strExamPlaceNo);
                    clip2 = clip2.And(View_ExamPlaceSpecialityKindsGroupMapping._.SpecialityKindsNO == strSpecialityKindsNO);

                    DataTable dt2 = DbHelper.GetDatabase().From<View_ExamPlaceSpecialityKindsGroupMapping>() //选择表
                                           .Select(View_ExamPlaceSpecialityKindsGroupMapping._.All)  //设置选择的字段数目 
                                           .Where(clip2)
                                           .OrderBy(new OrderByClip(View_ExamPlaceSpecialityKindsGroupMapping._.Sort))
                                           .ToDataTable();   //返回List
                    strExamTime = dt2.Rows[0]["GroupNo"].ToString().Trim();

                }
            }
            catch { }
            return strExamTime;
        }
        #endregion

        #region 时间轴 每个专业的考试流程日志
        public string GetExamLog(string strSignUpID, string strSpecialityKindsNO)
        {
            try
            {
                return DbHelper.GetDatabase().From<TB_Exam_Log>()
                      .Where(TB_Exam_Log._.SignUpID == strSignUpID && TB_Exam_Log._.SpecialityKindsNO == strSpecialityKindsNO)
                      .OrderBy(new OrderByClip(TB_Exam_Log._.NodeTime, OrderByOperater.DESC))
                      .Top(1)
                      .Select(TB_Exam_Log._.NodeName)
                      .ToScalar<string>();
            }
            catch
            {
                return "未获取到专业状态"; ;
            }
        }

        #endregion

        public JsonMessage SaveStudentRegistration(string JsonSignUpStudents, string JsonConsultUsers, string JsonExamSignUpStudentsSpeciality)
        {
            JsonMessage message = new JsonMessage();
            TB_SignUpStudents model = null;
            TB_ConsultUsers modelUser = null;
            TB_Exam_SignUpStudentsSpeciality modelExam = null;
            if (!JsonSignUpStudents.IsNullOrEmptyString())
            {
                model = JsonSignUpStudents.ToList<TB_SignUpStudents>();
            }
            if (!JsonConsultUsers.IsNullOrEmptyString())
            {
                modelUser = JsonConsultUsers.ToList<TB_ConsultUsers>();
            }
            if (!JsonExamSignUpStudentsSpeciality.IsNullOrEmptyString())
            {
                modelExam = JsonExamSignUpStudentsSpeciality.ToList<TB_Exam_SignUpStudentsSpeciality>();
            }
            if (modelExam != null)
            {
                int rcount = dal.ToCount<TB_Exam_SignUpStudentsSpeciality>(TB_Exam_SignUpStudentsSpeciality._.SignUpID == modelExam.SignUpID
                                    && TB_Exam_SignUpStudentsSpeciality._.SpecialityKindsNO == modelExam.SpecialityKindsNO
                                    && TB_Exam_SignUpStudentsSpeciality._.IsActive == "1");
                if (rcount > 0)
                {
                    message.State = "false";
                    message.Msg = "该专业已经报了，不能重复进行报名！";
                    return message;
                }

            }
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                if (model != null)
                {
                    dal.Save<TB_SignUpStudents>(model, trans);
                }
                if (modelUser != null)
                {
                    dal.Save<TB_ConsultUsers>(modelUser, trans);
                }
                if (modelExam != null)
                {
                    dal.Save<TB_Exam_SignUpStudentsSpeciality>(modelExam, trans);
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public JsonMessage ComplateStudentRegistration(string JsonSignUpStudents, string JsonExamSignUpStudentsSpeciality, string strUserID)
        {
            JsonMessage message = new JsonMessage();
            TB_SignUpStudents model = null;
            List<TB_Exam_SignUpStudentsSpeciality> list = null;
            if (!JsonSignUpStudents.IsNullOrEmptyString())
            {
                model = JsonSignUpStudents.ToList<TB_SignUpStudents>();
            }
            if (!JsonExamSignUpStudentsSpeciality.IsNullOrEmptyString())
            {
                list = JsonExamSignUpStudentsSpeciality.ToList<List<TB_Exam_SignUpStudentsSpeciality>>();
            }
            if (model == null)
            {
                message.State = "false";
                message.Msg = "没有找到对应的考生信息";
                return message;
            }
            if (list == null || list.Count == 0)
            {
                message.State = "false";
                message.Msg = "没有找到对应的考生报考专业信息";
                return message;
            }

            List<TB_Exam_SignUpStudentsSpeciality> listSpec = new List<TB_Exam_SignUpStudentsSpeciality>();

            TB_SignUpStudentsNetPayFee_Head modelFee = new TB_SignUpStudentsNetPayFee_Head();
            List<TB_SignUpStudentsNetPayFee_Detail> PayFee_DetailList = new List<TB_SignUpStudentsNetPayFee_Detail>();
            modelFee.SignUpID = model.SignUpID;
            modelFee.OrdNO = daoComm.CreateOrderNo();
            modelFee.PaySource = ConstPaySource.XJ;//现金
            modelFee.ExamYear = model.ExamYear;
            modelFee.ChargDate = DateTime.Now;
            modelFee.IsFee = "1";
            modelFee.IsFeeSuccess = "1";
            modelFee.ChargeUserID = strUserID;
            decimal sumMoney = 0;
            List<TB_Exam_Log> listLog = new List<TB_Exam_Log>();
            foreach (TB_Exam_SignUpStudentsSpeciality modelExam in list)
            {
                TB_Sys_SpecialityKinds modelZY = ServiceHelper.CreateBaseService().GetSpecialityKindsModel(modelExam.SpecialityKindsNO);
                if (modelZY == null)
                {
                    message.State = "false";
                    message.Msg = "没有找到对应的专业信息";
                    return message;
                }
                string strExamTime = GetExamTime(modelExam.ExamPlaceNO, modelExam.SpecialityKindsNO);
                //TB_Exam_SignUpStudentsSpeciality modelExamNew = dal.GetModel<TB_Exam_SignUpStudentsSpeciality>(TB_Exam_SignUpStudentsSpeciality._.SignUpStudentsSpecialityID == modelExam.SignUpStudentsSpecialityID);
                TB_Exam_SignUpStudentsSpeciality modelExamNew = DbHelper.GetDatabase().From<TB_Exam_SignUpStudentsSpeciality>().Where(TB_Exam_SignUpStudentsSpeciality._.SignUpStudentsSpecialityID == modelExam.SignUpStudentsSpecialityID).ToFirst();
                if (modelExamNew != null)
                {
                    modelExamNew.Attach();
                    modelExamNew.SignUpStudentsSpecialityID = modelExam.SignUpStudentsSpecialityID;
                    modelExamNew.AppointmentGroup_First = strExamTime;
                    modelExamNew.ExamLevel = ConstExamLevel.CS_Value;
                    modelExamNew.IsFee_First = ConstAppConfig.YJF_Value;
                    modelExamNew.AllowExamID = daoComm.CreateExamAllowExamID(modelExam.ExamPlaceNO, modelExam.SpecialityKindsNO, modelExam.ExamYear);
                    modelExamNew.ExamState = ConstAppConfig.WKS_Value;
                    modelExamNew.IsPass = ConstAppConfig.WTG_Value;
                    modelExamNew.OrderNo_First = modelFee.OrdNO;
                    modelExamNew.IsActive = "1";
                    modelExamNew.ExamPlaceNO = modelExam.ExamPlaceNO;//考点
                    modelExamNew.SpecialityKindsNO = modelExam.SpecialityKindsNO;
                    modelExamNew.AppointmentGroupTime_First = DateTime.Now;
                    listSpec.Add(modelExamNew);
                }
                TB_Exam_Log log = new TB_Exam_Log();
                log.AllowExamID = modelExamNew.AllowExamID;
                log.ExamLevel = 1;
                log.ExamPlaceNO = modelExamNew.ExamPlaceNO;
                log.IsPass = 0;
                log.NodeName = "报名";
                log.NodeTime = DateTime.Now;
                log.SignUpID = modelExamNew.SignUpID;
                log.SignUpStudentsSpecialityID = modelExamNew.SignUpStudentsSpecialityID;
                log.SpecialityKindsName = modelZY.SpecialityKindsName;
                log.SpecialityKindsNO = modelExamNew.SpecialityKindsNO;
                listLog.Add(log);

                TB_SignUpStudentsNetPayFee_Detail modelDetailFee = new TB_SignUpStudentsNetPayFee_Detail();
                modelDetailFee.OrdNO = modelFee.OrdNO;
                modelDetailFee.ExamLevel = ConstExamLevel.CS_Value;
                modelDetailFee.SpecialityKindsNO = modelExam.SpecialityKindsNO;
                modelDetailFee.Fee = modelZY.Fee_First.ToSafeDecimal();
                modelDetailFee.CounterFee = modelZY.CounterFee_First.ToSafeDecimal();
                modelDetailFee.ExamYear = modelExam.ExamYear;
                modelDetailFee.ExamPlaceNO = modelExam.ExamPlaceNO;
                modelDetailFee.ChargeUserID = strUserID;
                try
                {
                    modelDetailFee.ChargeIP = HttpContext.Current.Request.UserHostAddress;
                }
                catch
                { }
                modelDetailFee.ExamTime = strExamTime;
                PayFee_DetailList.Add(modelDetailFee);
                sumMoney = sumMoney + modelDetailFee.Fee.ToSafeDecimal() + modelDetailFee.CounterFee.ToSafeDecimal();
            }
            modelFee.Sum_Charge = sumMoney;

            TB_PrintList printListModel = new TB_PrintList();
            printListModel.SignUpID = model.SignUpID;
            try
            {
                printListModel.ComputerName = HttpContext.Current.Request.ServerVariables.GetValues("REMOTE_HOST")[0];
            }
            catch
            { }
            printListModel.IsPrint = "1";
            printListModel.CreateTime = DateTime.Now;
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                if (model != null)
                {
                    dal.Save<TB_SignUpStudents>(model, trans);
                }
                if (listSpec != null)
                {
                    foreach (TB_Exam_SignUpStudentsSpeciality modelExam in listSpec)
                    {
                        dal.Save<TB_Exam_SignUpStudentsSpeciality>(modelExam, trans);
                    }
                }
                if (modelFee != null)
                {
                    dal.Save<TB_SignUpStudentsNetPayFee_Head>(modelFee, trans);
                }
                if (PayFee_DetailList != null)
                {
                    foreach (TB_SignUpStudentsNetPayFee_Detail modelDetailFee in PayFee_DetailList)
                    {
                        dal.Save<TB_SignUpStudentsNetPayFee_Detail>(modelDetailFee, trans);
                    }
                }
                if (listLog != null)
                {
                    foreach (TB_Exam_Log log in listLog)
                    {
                        dal.Save<TB_Exam_Log>(log, trans);
                    }
                }
                dal.Save<TB_PrintList>(printListModel, trans);
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public JsonMessage UpdateSignUpStudentsSpeciality_TZ(string strSignUpStudentsSpecialityID, string strUpdateMessage, string strUserID)
        {
            string strClientIP = HttpContext.Current.Request.UserHostAddress;
            JsonMessage message = new JsonMessage();
            //读取原来的报考专业
            TB_Exam_SignUpStudentsSpeciality modelExam = dal.GetModel<TB_Exam_SignUpStudentsSpeciality>(TB_Exam_SignUpStudentsSpeciality._.SignUpStudentsSpecialityID == strSignUpStudentsSpecialityID);
            modelExam.Memo_First = strUpdateMessage;//原因
            modelExam.IsActive = "0";//改成无效
            if (string.IsNullOrEmpty(modelExam.IsFee_First) || modelExam.IsFee_First == "0")//没有缴费
            {
                message.State = "true";
                message.Msg = "保存成功!";
                dal.Save<TB_Exam_SignUpStudentsSpeciality>(modelExam);
                return message;
            }
            string strYear = modelExam.ExamYear;
            #region 生成负数订单
            TB_SignUpStudentsNetPayFee_Head modelFee_F = new TB_SignUpStudentsNetPayFee_Head();
            modelFee_F.SignUpID = modelExam.SignUpID;
            modelFee_F.OrdNO = daoComm.CreateOrderNo();
            modelFee_F.PaySource = ConstPaySource.XJ;//现金
            modelFee_F.ExamYear = modelExam.ExamYear;
            modelFee_F.ChargDate = DateTime.Now;
            modelFee_F.IsFee = "1";
            modelFee_F.IsFeeSuccess = "1";
            modelFee_F.ChargeUserID = strUserID;
            modelFee_F.ChargeIP = strClientIP;
            #endregion

            #region 生成负数订单明细
            TB_SignUpStudentsNetPayFee_Detail FeeDetailList_F = new TB_SignUpStudentsNetPayFee_Detail();
            decimal sumMoney = 0;
            FeeDetailList_F.OrdNO = modelFee_F.OrdNO;
            FeeDetailList_F.ExamLevel = ConstExamLevel.CS_Value;
            FeeDetailList_F.SpecialityKindsNO = modelExam.SpecialityKindsNO;
            TB_Sys_SpecialityKinds modelZY = ServiceHelper.CreateBaseService().GetSpecialityKindsModel(modelExam.SpecialityKindsNO);
            if (modelZY == null)
            {
                message.State = "false";
                message.Msg = "没有找到对应的专业信息";
                return message;
            }
            FeeDetailList_F.Fee = modelZY.Fee_First.ToSafeDecimal() * (-1);
            FeeDetailList_F.CounterFee = modelZY.CounterFee_First.ToSafeDecimal() * (-1);
            FeeDetailList_F.ExamYear = modelExam.ExamYear;
            FeeDetailList_F.ExamPlaceNO = modelExam.ExamPlaceNO;
            FeeDetailList_F.ChargeUserID = strUserID;
            FeeDetailList_F.Remark = strUpdateMessage;
            FeeDetailList_F.ChargeIP = strClientIP;
            FeeDetailList_F.ExamTime = modelExam.AppointmentGroup_First;
            sumMoney = sumMoney + FeeDetailList_F.Fee.ToSafeDecimal() + FeeDetailList_F.CounterFee.ToSafeDecimal();
            modelFee_F.Sum_Charge = sumMoney;
            #endregion

            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                if (modelExam != null)
                {
                    dal.Save<TB_Exam_SignUpStudentsSpeciality>(modelExam, trans);
                }
                if (modelFee_F != null)
                {
                    dal.Save<TB_SignUpStudentsNetPayFee_Head>(modelFee_F, trans);
                }
                if (FeeDetailList_F != null)
                {
                    dal.Save<TB_SignUpStudentsNetPayFee_Detail>(FeeDetailList_F, trans);
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public JsonMessage UpdateSignUpStudentsSpeciality(string strSignUpStudentsSpecialityID, string strExamPlaceNo, string strSpecNo,
            string strUpdateMessage, string strUserID)
        {
            JsonMessage message = new JsonMessage();
            //读取原来的报考专业
            TB_Exam_SignUpStudentsSpeciality modelExam = dal.GetModel<TB_Exam_SignUpStudentsSpeciality>(TB_Exam_SignUpStudentsSpeciality._.SignUpStudentsSpecialityID
                == strSignUpStudentsSpecialityID);

            TB_Exam_SignUpStudentsSpeciality modelExamNew = null;
            if (modelExam.IsFee_First == "0" || string.IsNullOrEmpty(modelExam.IsFee_First))//没有缴费
            {
                #region 生成新的报考信息
                modelExamNew = new TB_Exam_SignUpStudentsSpeciality();
                modelExamNew.AppointmentGroup_First = "";
                modelExamNew.AppointmentGroupTime_First = DateTime.Now;
                modelExamNew.ExamYear = modelExam.ExamYear;
                modelExamNew.ExamLevel = ConstExamLevel.CS_Value;
                modelExamNew.IsFee_First = ConstAppConfig.WJF_Value;
                modelExamNew.SignUpID = modelExam.SignUpID;
                modelExamNew.ExamPlaceNO = strExamPlaceNo;
                modelExamNew.SpecialityKindsNO = strSpecNo;
                modelExamNew.IsActive = "1";
                modelExamNew.SignUpType = ConstPaySource.XC;
                modelExamNew.CreatTime = DateTime.Now;
                modelExamNew.ExamState = ConstAppConfig.WKS_Value;
                modelExamNew.IsPass = ConstAppConfig.WTG_Value;
                #endregion
                dal.Save<TB_Exam_SignUpStudentsSpeciality>(modelExamNew);
                message.State = "true";
                message.Msg = "保存成功!";
                return message;
            }

            int rcount = dal.ToCount<TB_Exam_SignUpStudentsSpeciality>(TB_Exam_SignUpStudentsSpeciality._.SignUpID == modelExam.SignUpID
                                && TB_Exam_SignUpStudentsSpeciality._.SpecialityKindsNO == strSpecNo
                                && TB_Exam_SignUpStudentsSpeciality._.IsActive == "1");
            if (rcount > 0)
            {
                message.State = "false";
                message.Msg = "该专业已经报了，不能重复进行报名！";
                return message;
            }
            string strClientIP = HttpContext.Current.Request.UserHostAddress;
            string strExamTime = GetExamTime(strExamPlaceNo, strSpecNo);
            string strYear = modelExam.ExamYear;
            #region 生成新的报考信息
            modelExamNew = new TB_Exam_SignUpStudentsSpeciality();
            modelExamNew.AppointmentGroup_First = strExamTime;
            modelExamNew.AppointmentGroupTime_First = DateTime.Now;
            modelExamNew.ExamYear = strYear;
            modelExamNew.ExamLevel = ConstExamLevel.CS_Value;
            modelExamNew.IsFee_First = ConstAppConfig.YJF_Value;
            modelExamNew.AllowExamID = daoComm.CreateExamAllowExamID(strExamPlaceNo, strSpecNo, strYear);
            modelExamNew.ExamState = ConstAppConfig.WKS_Value;
            modelExamNew.IsPass = ConstAppConfig.WTG_Value;
            modelExamNew.SignUpID = modelExam.SignUpID;
            modelExamNew.ExamPlaceNO = strExamPlaceNo;
            modelExamNew.SpecialityKindsNO = strSpecNo;
            modelExamNew.IsActive = "1";
            modelExamNew.SignUpType = ConstPaySource.XC;
            modelExamNew.CreatTime = DateTime.Now;
            string strOrderNo = daoComm.CreateOrderNo();
            modelExamNew.OrderNo_First = strOrderNo;
            #endregion

            #region 生成新订单
            TB_SignUpStudentsNetPayFee_Head modelFee = new TB_SignUpStudentsNetPayFee_Head();
            modelFee.SignUpID = modelExamNew.SignUpID;
            modelFee.OrdNO = strOrderNo;
            modelFee.PaySource = ConstPaySource.XJ;//现金
            modelFee.ExamYear = modelExam.ExamYear;
            modelFee.ChargDate = DateTime.Now;
            modelFee.IsFee = "1";
            modelFee.IsFeeSuccess = "1";
            modelFee.ChargeUserID = strUserID;
            modelFee.ChargeIP = strClientIP;
            #endregion

            #region 生成负数订单明细
            TB_SignUpStudentsNetPayFee_Detail FeeDetailList = new TB_SignUpStudentsNetPayFee_Detail();
            decimal sumMoney = 0;
            FeeDetailList.OrdNO = modelFee.OrdNO;
            FeeDetailList.ExamLevel = ConstExamLevel.CS_Value;
            FeeDetailList.SpecialityKindsNO = modelExamNew.SpecialityKindsNO;
            TB_Sys_SpecialityKinds modelZY = ServiceHelper.CreateBaseService().GetSpecialityKindsModel(modelExamNew.SpecialityKindsNO);
            if (modelZY == null)
            {
                message.State = "false";
                message.Msg = "没有找到对应的专业信息";
                return message;
            }
            FeeDetailList.Fee = modelZY.Fee_First.ToSafeDecimal();
            FeeDetailList.CounterFee = modelZY.CounterFee_First.ToSafeDecimal();
            FeeDetailList.ExamYear = modelExamNew.ExamYear;
            FeeDetailList.ExamPlaceNO = modelExamNew.ExamPlaceNO;
            FeeDetailList.ChargeUserID = strUserID;
            FeeDetailList.ChargeIP = strClientIP;
            FeeDetailList.ExamTime = strExamTime;
            sumMoney = sumMoney + FeeDetailList.Fee.ToSafeDecimal() + FeeDetailList.CounterFee.ToSafeDecimal();
            modelFee.Sum_Charge = sumMoney;
            #endregion

            TB_PrintList printListModel = new TB_PrintList();
            printListModel.SignUpID = modelExamNew.SignUpID;
            try
            {
                printListModel.ComputerName = HttpContext.Current.Request.ServerVariables.GetValues("REMOTE_HOST")[0];
            }
            catch
            { }
            printListModel.IsPrint = "1";
            printListModel.CreateTime = DateTime.Now;
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                if (modelExamNew != null)
                {
                    dal.Save<TB_Exam_SignUpStudentsSpeciality>(modelExamNew, trans);
                }
                if (modelFee != null)
                {
                    dal.Save<TB_SignUpStudentsNetPayFee_Head>(modelFee, trans);
                }
                if (FeeDetailList != null)
                {
                    dal.Save<TB_SignUpStudentsNetPayFee_Detail>(FeeDetailList, trans);
                }
                dal.Save<TB_PrintList>(printListModel, trans);
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }


            return message;
        }

        public DataTable GetExamSigned(string strSignUpStudentsSpecialityID)
        {
            return dal.GetTable<TB_Exam_Signed>(TB_Exam_Signed._.SignUpStudentsSpecialityID == strSignUpStudentsSpecialityID);
        }


        public JsonMessage ImportUploadPhoto(string serchVal)
        {
            JsonMessage message = new JsonMessage();
            TB_SignUpStudentsPhoto model = null;
            try
            {
                model = JsonHelper.JsonDeserialize<TB_SignUpStudentsPhoto>(serchVal);
                if (model == null)
                {
                    throw new Exception("解析Json数据格式错误！");
                }
                else
                {
                    if (model.SignUpStudentsID != null)
                    {
                        TB_SignUpStudents modelSign = dal.GetModel<TB_SignUpStudents>(TB_SignUpStudents._.IdentityCard == model.SignUpStudentsID);
                        if (modelSign != null)
                        {
                            model.SignUpStudentsID = modelSign.SignUpID;
                        }
                    }
                    DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
                    try
                    {
                        dal.UploadPhoto(model, trans);
                        trans.Commit();
                        message.State = "true";
                        message.Msg = "保存成功!";
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        message.State = "false";
                        message.Msg = "保存失败," + ex.Message;
                        throw ex;
                    }
                    finally
                    {
                        trans.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage ImportSignUpStudents(string strSignUpStudents, string strSignUpStudentsExamSpec)
        {
            Dictionary<string, TB_SignUpStudents> dicSignUpStudentNew = null;
            List<TB_Exam_SignUpStudentsSpeciality> listSpecNew = null;
            JsonMessage message = new JsonMessage();
            try
            {
                dicSignUpStudentNew = JsonHelper.JsonToObject<Dictionary<string, TB_SignUpStudents>>(strSignUpStudents);
                listSpecNew = JsonHelper.JsonToObject<List<TB_Exam_SignUpStudentsSpeciality>>(strSignUpStudentsExamSpec);
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "数据Json格式化出现错误：" + ex.Message;
                return message;
            }
            if (dicSignUpStudentNew != null && listSpecNew != null)
            {
                DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
                try
                {
                    foreach (KeyValuePair<string, TB_SignUpStudents> key in dicSignUpStudentNew)
                    {
                        if (dal.GetModel<TB_SignUpStudents>(TB_SignUpStudents._.NMT_SignUpID == key.Value.NMT_SignUpID) == null)
                        {
                            dal.Save<TB_SignUpStudents>(key.Value, trans);
                        }
                    }
                    foreach (TB_Exam_SignUpStudentsSpeciality model in listSpecNew)
                    {
                        dal.Save<TB_Exam_SignUpStudentsSpeciality>(model, trans);
                    }
                    trans.Commit();
                    message.State = "true";
                    message.Msg = "批量导入成功!";
                }

                catch (Exception ex)
                {
                    trans.Rollback();
                    message.State = "false";
                    message.Msg = "批量导入失败," + ex.Message;
                }
                finally
                {
                    trans.Close();
                }
            }
            else
            {
                message.State = "false";
                message.Msg = "数据Json格式化出现错误";
                return message;
            }
            return message;

        }
    }
}
